package typejump.objects;

import typejump.AnimationManager;
import typejump.engine.CollisionProps;

public class Llamow extends Actor {

	private double boredomTimer = 0;
	private double boredomReset = 2;

	private static final int FACE_LEFT = 1;
	private static final int FACE_RIGHT = -1;
	private int face = FACE_LEFT; // facing left
	private double visibility = 200;
	
	public Llamow() {
		super("Llamow");
		setCollision(CollisionProps.T_NPC, CollisionProps.T_ITEM|CollisionProps.T_GEOM|CollisionProps.T_PC);
		setDefaultAnimation(AnimationManager.LLAMOW_IDLE);
		putAnimation("sitdown", AnimationManager.LLAMOW_SIT);
		putAnimation("sitting", AnimationManager.LLAMOW_SITTING);
		putAnimation("standup", AnimationManager.LLAMOW_STAND);
		setMaxHealth(10);
		scaleToImage();
	}
	
	public String generateSpawnCommand() {
		return "";
	}
	
	public boolean canSee(GameObject other) {
		if (Math.abs(centerX() - other.centerX()) > visibility)
			return false;
		if (face == FACE_LEFT) {
			return other.left() < left();
		} else if (face == FACE_RIGHT) {
			return other.right() > right();
		}
		return false;
	}
	
	@Override
	public boolean intersects(GameObject other) {
		if (super.intersects(other)) return true;
		if (other instanceof Player) {
			return canSee(other);
		}
		return false;
	}
	
	public static Llamow createObject(String params) {
		Llamow llamow = new Llamow();
		return llamow;
	}
	
	public void update(double time) {
		super.update(time);
		if (boredomTimer > 0) {
			boredomTimer -= time;
			if (boredomTimer <= 0) {
				animate("play sitdown ; loop sitting");
			}
		}
	}

	
	public void collide(GameObject other) {
		super.collide(other);
		
		if (other instanceof Player) {
			boredomTimer = boredomReset;
			if (getAnimationName().equals("sitting")) {
				animate("play standup");
			}
			
			if (super.intersects(other)) {
				Player p = (Player)other;
				p.damage(10);
			}
		}
	}
}
